import math
def is_prime(num):
    if num < 2:
        return False
    for i in range(2, int(math.sqrt(num)) + 1):
        if num % i == 0:
            return False
    return True
words_to_numbers = {
    "zero": 0,
    "one": 1,
    "two": 2,
    "three": 3,
    "four": 4,
    "five": 5,
    "six": 6,
    "seven": 7,
    "eight": 8,
    "nine": 9
}
words = input().split()
if len(words) != 3:
    print("Wrong input")
else:
    num = 100 * words_to_numbers.get(words[0], -1) + 10 * words_to_numbers.get(words[1], -1) + words_to_numbers.get(words[2], -1)
    if num <= 100 or num >= 999:
        print("Wrong input")
    else:
        lower_prime = num
        upper_prime = num
        while not is_prime(lower_prime):
            lower_prime -= 1
        while not is_prime(upper_prime):
            upper_prime += 1
        if num - lower_prime > upper_prime - num:
            print(upper_prime)
        else:
            print(lower_prime)